package com.xiaoyun.seleniumlinux.config.mq;

import com.xiaoyun.seleniumlinux.enums.MqConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitMQ消息队列配置类
 *
 * @author 芋道源码
 */
@Configuration
@Slf4j
@EnableRabbit
public class RabbitConfiguration {
    /**
     * 配置消息json 序列化
     *
     * @return
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }


    @Bean
    public Queue queueSeleniumSuccess() {
        return new Queue(MqConstants.QUEUE_SELENIUM_SUCCESS, true);
    }

    /**
     * 准备一个交换机
     *
     * @return
     */
    @Bean
    public FanoutExchange exchangeSeleniumSuccess() {
        return new FanoutExchange(MqConstants.EXCHANGE_SELENIUM_SUCCESS);
    }

    /**
     * 将交换机和队列进行绑定
     *
     * @return
     */
    @Bean
    public Binding bindingExchangeSeleniumSuccess() {
        return BindingBuilder.bind(queueSeleniumSuccess()).to(exchangeSeleniumSuccess());
    }

    @Bean
    public Queue queueSelenium() {
        return new Queue(MqConstants.QUEUE_SELENIUM,true);
    }

    /**
     * 准备一个交换机
     *
     * @return
     */
    @Bean
    public FanoutExchange exchangeSelenium() {
        return new FanoutExchange(MqConstants.EXCHANGE_SELENIUM);
    }


    /**
     * 将交换机和队列进行绑定
     *
     * @return
     */
    @Bean
    public Binding bindingExchangeSelenium() {
        return BindingBuilder.bind(queueSelenium()).to(exchangeSelenium());
    }

}
